package day01;

import java.io.*;

class User implements Serializable{
    private final static long serialVersionUID = 1;
    private String name;
    private boolean gender;
    private int age;
    private String mobile;
    private String addr;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isGender() {
        return gender;
    }

    public void setGender(boolean gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public User(String name, boolean gender, int age, String mobile, String addr) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.mobile = mobile;
        this.addr = addr;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", gender=" + (gender?"男":"女") +
                ", age=" + age +
                ", mobile='" + mobile + '\'' +
                ", addr='" + addr + '\'' +
                '}';
    }
}


public class ObjectInputOutputStreamDemo01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oout = new ObjectOutputStream(
                new FileOutputStream(new File("D:\\1\\object.txt")));
        User user = new User("张三",true,21,"139","南京");
        oout.writeObject(user);
        User user2 = new User("李四",false,18,"155","上海");
        oout.writeObject(user2);
        oout.close();
        ObjectInputStream oin = new ObjectInputStream(
                new FileInputStream(
                        new File("D:\\1\\object.txt")
                ));
        User u1 = (User)oin.readObject();
        System.out.println(u1);
        User u2 = (User)oin.readObject();
        System.out.println(u2);


    }

}
